//
//  TraderMiddleManCell.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/4/17.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//  经纪人账号cell

#import "TraderMiddleManCell.h"

#define SCALE UIScreenWidth/320.0
@interface TraderMiddleManCell()
@property (weak, nonatomic) IBOutlet UIButton *thirdBtn;

@property (weak, nonatomic) IBOutlet UIView *mainView;
//禁用，启用按钮
@property (weak, nonatomic) IBOutlet UIButton *secondBtn;
//竖的分割线
@property (weak, nonatomic) IBOutlet UIView *fengeLine;
//返回剪头的img
@property (weak, nonatomic) IBOutlet UIImageView *backImg;
//经纪人名称
@property (weak, nonatomic) IBOutlet UILabel *name;
//公司名称
@property (weak, nonatomic) IBOutlet UILabel *company;
//手机号码
@property (weak, nonatomic) IBOutlet UILabel *phone;
//用户头像
@property (weak, nonatomic) IBOutlet UIImageView *peopleImg;
//打勾图片
@property (weak, nonatomic) IBOutlet UIImageView *markImg;
//已禁用
@property (weak, nonatomic) IBOutlet UILabel *forbiddenLab;

- (IBAction)hiddenThreeBtn:(id)sender;
//0:编辑、1:禁用、2移动
-(IBAction) clickBtn:(UIButton *)btn;

@property(nonatomic,assign) NSInteger row;
//flag = 0 只显示信息，= 1 显示打勾图片
@property(nonatomic,assign) NSInteger  flag;
@property (weak, nonatomic) IBOutlet UIView *view2;

@property (weak, nonatomic) IBOutlet UIControl *view1;

@property(nonatomic,assign) BOOL isMiddleMan;//是否是经纪人角色

@end
@implementation TraderMiddleManCell


//-(void)layoutSubviews
//{
//    [super layoutSubviews];
//    self.view1.frame = CGRectMake(30*SCALE, 0, UIScreenWidth, 44);
//    self.view2.frame = CGRectMake(350*SCALE, 0, 130*SCALE, 44);
//    self.mainView.frame = CGRectMake(-30*SCALE, 0, 480*SCALE, 44);
//    
//    
//    if (self.isMiddleMan)
//    {
//        [self.thirdBtn setTitle:@"绑定楼盘" forState:UIControlStateNormal];
//        [self.thirdBtn setTitleColor:[UIColor colorWithRed:78/255.0 green:182/255.0 blue:250/255.0 alpha:1] forState:UIControlStateNormal];
//    }
//    else
//    {
//        [self.thirdBtn setTitle:@"移动" forState:UIControlStateNormal];
//        [self.thirdBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:109/255.0 blue:250/255.0 alpha:1] forState:UIControlStateNormal];
//        
//    }
//    
//    
//    
//    
//    
//    
//
//}
+(instancetype)cellWithTableView:(UITableView *)tableView withRow:(NSInteger)row withlabShow:(BOOL)isShowLab withIsMiddleMan:(BOOL)isMiddleMan;
{
    static NSString *ID = @"traderMiddleManCell";
   
    TraderMiddleManCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil)
    {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"TraderMiddleManCell" owner:nil options:nil]lastObject];
    }
    cell.row = row;
    cell.isMiddleMan = isMiddleMan;
    

    if (isShowLab)
    {
        cell.company.hidden = NO;
    }
    else
    {
        cell.company.hidden = YES;
    }
        return cell;
}
- (void)awakeFromNib
{
    
//    [super awakeFromNib];
    
    self.flag = 0;
    
    self.forbiddenLab.hidden = YES;
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeCell:)];
    swipe.direction = UISwipeGestureRecognizerDirectionLeft;
    [self addGestureRecognizer:swipe];
    
   
    //把打勾图片移动屏幕上
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(moveTickBtnToSee) name:@"moveTickBtnToSee" object:nil];
    //把打勾图片移除屏幕
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(moveTickBtnToNotSee) name:@"moveTickBtnToNotSee" object:nil];
    //把打勾图片都打勾
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(respondToSelectAllMiddleMan:) name:@"selectAllMiddleMan" object:nil];
    //已禁用
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(respondToForbiddenMiddleMan:) name:@"forbiddenMiddleMan" object:nil];
    

    
}

-(void)test
{
     NSLog(@"%d",self.isEdit);
    if (self.isEdit)
    {
        [self moveTickBtnToSee];
    }else
    {
        [self moveTickBtnToNotSee];
    }

}

-(void)respondToForbiddenMiddleMan:(NSNotification *)notify
{
    NSNumber *tagNum = [notify object];
    NSInteger tag = [tagNum  integerValue];
    
    if (tag == 2)
    {
        self.forbiddenLab.hidden = YES;
    }else
    {
        self.forbiddenLab.hidden = NO;
    }
}
-(void)respondToSelectAllMiddleMan:(NSNotification *)notify
{
    NSNumber *imgNum = [notify object];
    NSInteger tag = [imgNum integerValue];
    if (tag == 1)
    {
        [self selectCell];
    }else
    {
        [self deSelectCell];
    }

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
#pragma mark 处理滑动事件
-(void)swipeCell:(UISwipeGestureRecognizer *)gesture
{
    if (self.flag ==0)
    {
        self.mainView.frame = CGRectMake(-157*(UIScreenWidth/320.0), 0,480*(UIScreenWidth/320.0), 44);
    }
    
}

-(void)moveTickBtnToSee
{
    self.flag = 1;
    self.mainView.frame = CGRectMake(0, 0,480*(UIScreenWidth/320.0), 44);
}
-(void)moveTickBtnToNotSee
{
     self.flag = 0;
    [self hiddenThreeBtn:nil];
    
    [self deSelectCell];
   
}


-(IBAction) clickBtn:(UIButton *)btn;
{
    
//    NSLog(@"客户管理%d",self.row);
}

- (IBAction)hiddenThreeBtn:(id)sender {
    if (self.flag == 0)
    {
        self.mainView.frame = CGRectMake(-30*(UIScreenWidth/320.0), 0,480*(UIScreenWidth/320.0), 44);
    }else
    {
        [self respondMarkImg];
    }
    
}

#pragma mark 切换cell打勾 或者不打勾
-(void)respondMarkImg
{
    if( self.markImg.tag == 0)
    {
        [self selectCell];
    }else
    {
        [self deSelectCell];
    }

}

#pragma mark 让cell打勾
-(void)selectCell
{
    self.markImg.image = [UIImage imageNamed:@"fuxuan_birder_si"];
    self.markImg.tag = 1;
}
#pragma mark cell不打勾
-(void)deSelectCell
{
    self.markImg.image = [UIImage imageNamed:@"fuxuan_birder"];
    self.markImg.tag = 0;
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
